using System;
using System.Web;
using System.Collections.Generic;
using System.Text;

using System.Text.RegularExpressions;

namespace ProjectBase.Utils
{
    public class CString
    {
        //string.re
        static public string BadWordReplace(string SearchText)
        {
            string strReturn = SearchText;
            //RegexOptions options = RegexOptions.IgnoreCase /*| RegexOptions.Singleline | RegexOptions.Multiline*/;

            //// rico : run word replacement from database table names yaf_replacewords
            //DataTable dt = (DataTable)HttpContext.Current.Cache["replacewords"];
            //if (dt == null)
            //{
            //    dt = DB.replace_words_list();
            //    HttpContext.Current.Cache.Insert("replacewords", dt, null, DateTime.Now.AddMinutes(15), TimeSpan.Zero);
            //}
            //foreach (DataRow rwords in dt.Rows)
            //{
            //    try
            //    {
            //        strReturn = Regex.Replace(strReturn, Convert.ToString(rwords["badword"]), Convert.ToString(rwords["goodword"]), options);
            //    }
            //    catch (Exception e)
            //    {
            //        throw new Exception("Regular Expression Failed: " + e.Message);
            //    }
            //}

            return strReturn;
        }

        public static bool CheckGroupDefault(string groupid)
        {
            String[] ids = groupid.Split(new Char[] { ',' });
            for (int i = 0; i < ids.Length; i++)
            {
                if (ids[i] == "0")
                {
                    return true;
                }
            }
            return false;
        }

        public static string XauHienThiBR(string src)
        {

            string Ketqua = "";
            if (src == null) return "";
            if (src.Trim() != "")
            {
                Ketqua = HttpContext.Current.Server.HtmlEncode(src);
                string se1 = Convert.ToChar('\u000D').ToString();
                string se2 = Convert.ToChar('\u000A').ToString();
                string se3 = se1 + se2;
                string se4 = Convert.ToChar('\u2028').ToString();
                string se5 = Convert.ToChar('\u2029').ToString();
                Ketqua = Ketqua.Replace(se4, "<br>");
                Ketqua = Ketqua.Replace(se5, "<br>");
                Ketqua = Ketqua.Replace(se3, "<br>");
                Ketqua = Ketqua.Replace(se1, "<br>");
                Ketqua = Ketqua.Replace(se2, "<br>");
                Ketqua = HttpContext.Current.Server.HtmlDecode(Ketqua);
            }
            return Ketqua;
        }

    }
}
